package com.yunji.common.enums.common;

import com.google.common.collect.Lists;
import com.yunji.common.base.BaseEnum;
import com.yunji.common.constant.PermissionTypeConstant;
import lombok.Getter;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/11/26 14:49
 * @description : TODO
 **/
@Getter
public enum PermissionTypeEnum implements BaseEnum<String> {
    BELONG(PermissionTypeConstant.DATA_SCOPE_BELONG, Lists.newArrayList("belong_id"), false),
    STORAGE_TWO(PermissionTypeConstant.DATA_SCOPE_STORAGE_TWO, Lists.newArrayList("belong_id", "out_belong_id"), false),
    STORAGE_THREE(PermissionTypeConstant.DATA_SCOPE_STORAGE_THREE, Lists.newArrayList("belong_id", "out_belong_id", "into_belong_id"), false),
    STORAGE_BELONG_IDS(PermissionTypeConstant.DATA_SCOPE_BELONG_IDS, Lists.newArrayList("belong_id", "out_belong_id", "into_belong_id"), true);

    PermissionTypeEnum(String code, List<String> columns, boolean requestParam) {
        this.code = code;
        this.columns = columns;
        this.requestParam = requestParam;
    }

    private final String code;
    private final List<String> columns;
    private final boolean requestParam;

    public static List<PermissionTypeEnum> getRequestTypes(String[] codes) {
        List<PermissionTypeEnum> requestTypes = Lists.newArrayList();
        for (String value : codes) {
            PermissionTypeEnum baseEnum = BaseEnum.getBaseEnum(PermissionTypeEnum.class, value);
            if (baseEnum != null && baseEnum.isRequestParam()) {
                requestTypes.add(baseEnum);
            }
        }
        return requestTypes;
    }
}
